Sending an Email

Description

This tutorial shows how to build an email client into your application. There are two pages. The first allows you to compose and send an email. The second page confirms a successfully sent message and allows you to return to the previous page to send another message.

The Sending an Email topic describes a technique available to Alpha Anywhere database users.
This example presumes that you have configured the internal Alpha Anywhere Email Client.

Creating the Email Send Page

  1. Create a new dialog component.

  2. Display the Form > Controls page.

  3. Place two Textbox controls on the dialog. Name them "to" and "subject".

  4. In the Selected Controls list choose "To".

    • 1.

    • 2.

      • General > Require value

      • Text Format > Allow letters

      • Text Format > Allow white space

      • Text Format > Allow digits

      • Text Format > Allow special characters

    • 3. Click OK to return to the Dialog Builder.

    • 4. Check Control Settings > Client side validation.

    • 5. Change TextBox Properties > Size to 80.

    • 6. Change TextBox Properties > MaxLength to 200.

  5. Make comparable changes for the Subject field.

  6. Place a TextArea control on the dialog and name it "message".

  7. In the Selected Controls list choose "message".

    • 1. Click the '...' button in the Control Settings > Validation rules field to display the Field Validation dialog box.

    • 2. Check the following fields:

      • General > Require value

      • Text Format > Allow letters

      • Text Format > Allow white space

      • Text Format > Allow digits

      • Text Format > Allow special characters

    • 3. Click OK to return to the Dialog Builder.

    • 4. Check Control Settings > Client side validation.

    • 5. Change TextArea Properties > Rows to 12.

    • 6. Change TextArea Properties > Columns to 79.

  8. Display the Form > Properties page.

    • Change the Submit/Reset Buttons > Submit button label to "Send Email".

    • Click the '...' in the Freeform Edit Regions > Above Dialog field to display the HTML Editor.

    • Enter "Send an Email Message". Set the style to "Heading 3", the font to "Comic Sans MS", and the size to "4 (14pt)".

    • Click Save.

    • Check Client Events > Validate before submit.

    • Click '...' in the Server Events > Validate field to display the Form Events dialog. Add the following code. This script uses the EMAIL_SEND() function to send the message.

      dim result as N
      result = email_send(to,subject,message)
      if (result <> 1) then
          CurrentForm.Has_Error = .T.
          CurrentForm.Error_Message = "Email was not sent."
      end if
    • Click '...' in the Server Events > AfterValidate field to display the Form Events dialog. Add the following code. The AfterValidate event only fires if there is no error in the Validate event.

      Currentform.RedirectTarget = "email_confirmation.a5w"
  9. Click Save, enter "Send_Email" into the File name field, and Save.

  10. Click Close.

  11. Select New > Alpha Anywhere Web Page > OK to display the HTML Editor.

  12. Click File > Save As, name the page "Send_Email" and click Save.

  13. Click Insert Component > Select.

  14. Pick the "Send_Email" component and click OK.

  15. Click Save and Close.

  16. Creating the Email Confirmation Page

    Display the Web Projects Control Panel.

  17. Select New > Alpha Anywhere Web Page > OK to display the HTML Editor.

  18. Display the Source tab. Enter the following content.

    <html>
    <head>
    <meta name="generator" content="Alpha Anywhere HTML Editor">
    <title></title>
    </head>
    <body>
    <p><font face=Tahoma>Your email message has been sent.</p>
    <p><a href="Send_Email.a5w">Send another email message</a></font>
    </p>
    </body>
    </html>
  19. Click File > Save As and name the page "Email_Confirmation".

  20. Close the HTML Editor.

  21. Testing the Pages

    Right click the "Email_Confirmation" component and select Publish (Local Webroot).

  22. Right click the "Send_Email.a5w" page and select Publish (Local Webroot) and open. The results should look like this.